﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;

namespace ExpressionUtil.Node.Common
{
    /// <summary>
    /// 一元节点
    /// </summary>
    [Serializable]
    internal abstract class UnitaryNode : Node, ISerializable
    {
        /// <summary>
        /// 操作数
        /// </summary>
        protected Node operand;

        /// <summary>
        /// 默认构造函数
        /// </summary>
        public UnitaryNode()
            : base()
        {
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="info">要填充数据的 System.Runtime.Serialization.SerializationInfo</param>
        /// <param name="context">此序列化的目标</param>
        public UnitaryNode(SerializationInfo info, StreamingContext context)
            : base()
        {
            this.operand = (Node)info.GetValue("operand", typeof(Node));
        }

        /// <summary>
        /// 获取或设置操作数
        /// </summary>
        public Node Operand
        {
            get
            {
                return this.operand;
            }
            set
            {
                this.operand = value;
            }
        }

        #region ISerializable 成员
        /// <summary>
        /// 获取对象数据
        /// </summary>
        /// <param name="info">要填充数据的 System.Runtime.Serialization.SerializationInfo</param>
        /// <param name="context">此序列化的目标</param>
        public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("operand", this.operand, typeof(Node));
        }

        #endregion
    }
}
